package org.luxor.common.netty.protocol;


import io.netty.util.internal.StringUtil;
import org.luxor.common.netty.constant.NettyReasonCode;
import org.luxor.commons.core.web.IRestStatus;

/**
 * Netty SendReply Message VariableHeader
 *
 * @author Mr.yan @date 2024/1/31
 */
public class NettySendReplyMessageVariableHeader extends NettyMessageIdVariableHeader {
    private final int reasonCode;
    private final String reasonMsg;

    public NettySendReplyMessageVariableHeader(String messageId, int reasonCode, String reasonMsg) {
        super(messageId);
        this.reasonCode = reasonCode;
        this.reasonMsg = reasonMsg;
    }

    public int reasonCode() {
        return this.reasonCode;
    }

    public String reasonMsg() {
        return this.reasonMsg;
    }

    public static NettySendReplyMessageVariableHeader from(String messageId, int errorCode, String errorMessage) {
        return new NettySendReplyMessageVariableHeader(messageId, errorCode, errorMessage);
    }

    public static NettySendReplyMessageVariableHeader from(String messageId, IRestStatus reasonStatus) {
        return NettySendReplyMessageVariableHeader.from(messageId, reasonStatus.code(), reasonStatus.message());
    }

    public static NettySendReplyMessageVariableHeader from(String messageId) {
        return NettySendReplyMessageVariableHeader.from(messageId, NettyReasonCode.SUCCESS.code(), NettyReasonCode.SUCCESS.message());
    }

    @Override
    public String toString() {
        return StringUtil.simpleClassName(this) +
                '[' +
                "messageId=" + super.messageId() +
                ", reasonCode=" + reasonCode +
                ", reasonMsg=" + reasonMsg +
                ']';
    }
}
